package com.shujia.sql

import org.apache.spark.sql.{DataFrame, SparkSession}

object Demo7OnHIve {
  def main(args: Array[String]): Unit = {

    val spark: SparkSession = SparkSession
      .builder()
      .appName("submit")
      .config("spark.sql.shuffle.partitions", 2)
      .enableHiveSupport() //开启读取hive的元数据
      .getOrCreate()

    /**
      * 可以直接使用hive中表
      *
      */

    spark.sql(
      """
        |show tables
        |
      """.stripMargin).show()


    spark.sql(
      """
        |
        |select clazz,count(1) from student group by clazz
        |
        |
      """.stripMargin).show()


    //可以读取hive中的表构建df
    val score: DataFrame = spark.table("score")
    score.show()

  }

}
